﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using Math.Compiler.Interfaces;
using System.Collections.Generic;

namespace Math.Compiler.AddIns
{
    [Function("COUNT")]
    internal class Count : IEnumerableFunction
    {
        public Func<IEnumerable<double>, double> Eval
        {
            get
            {
                return (a) =>
                {
                    int n = 1;
                    IEnumerator<double> enumerator = a.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        while (enumerator.MoveNext())
                        {
                            ++n;
                        }
                    }
                    return n;
                };
            }
        }
    }
}
